package edu.uoc.tfc.gui.common;



import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;



public class ResultatAccioAjaxVO implements Serializable
{

	private static final long serialVersionUID = 1L;
	private Collection<MissatgeAjax> messages = new ArrayList<MissatgeAjax>();
	private Level level = Level.Success;


	public Collection<MissatgeAjax> getMessages() {
		return this.messages;
	}




	public void addMessage(String key, String[] params, Level level) {
		MissatgeAjax m = new MissatgeAjax(key, params, level);
		addMessage(m);
	}



	public void addMessage(MissatgeAjax m) {
		this.messages.add(m);
		setLevel(m.getLevel());
	}



	public Level getLevel() {
		return this.level;
	}



	public void setLevel(Level level) {
		switch (level) {
			case Error:
				setError();
				break;
			case Warn:
				setWarn();
				break;
			case Info:
				setInfo();
				break;
			case Success:
				setSuccess();
				break;
		}
	}



	public void setError() {
		this.level = Level.Error;
	}



	public void setWarn() {
		if (this.level != Level.Error)
			this.level = Level.Warn;
	}



	public void setInfo() {
		if (
			this.level != Level.Error &&
			this.level != Level.Warn
		){
			this.level = Level.Info;
		}
	}



	public void setSuccess() {
		if (
			this.level != Level.Error &&
			this.level != Level.Warn &&
			this.level != Level.Info
		){
			this.level = Level.Success;
		}
	}



}
